#pragma once #define _USE_MATH_DEFINES #include namespace Dudnienie { ... ... ... #pragma endregion double A1,A2,W1,W2,F1,F2; static double Xp=-1.0, Xk=1.0, Yp=-1.0, Yk=1.0; int ex( double x) { return int((x-Xp)/(Xk-Xp)*pictureBox1->Width); } int ey( double y) { return int((Yk-y)/(Yk-Yp)*pictureBox1->Height); } double rzx( double x) { return Xp+(Xk-Xp)*x/pictureBox1->Width; } double rzy( double y) { return Yk-(Yk-Yp)*y/pictureBox1->Height; } // -------------------------------------------------------------------------- private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { A1=1.0; A2=1.0; W1=9.1; W2=9.8; F1=0.0; F2=0.0; panelSin1->BackColor=Color::Blue; panelSin2->BackColor=Color::Green; panelSin12->BackColor=Color::Red; textBox_Leave(sender,e); } // -------------------------------------------------------------------------- private: System::Void hScrollBar_Scroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e) { A1=0.01*hScrollBarA1->Value; A2=0.01*hScrollBarA2->Value; W1=0.1*hScrollBarW1->Value; W2=0.1*hScrollBarW2->Value; F1=hScrollBarF1->Value*M_PI/180.0; F2=hScrollBarF2->Value*M_PI/180.0; labelA1->Text=L"A1 = "+A1.ToString("F2"); labelA2->Text=L"A2 = "+A2.ToString("F2"); labelW1->Text=L"W1 = "+W1.ToString("F2"); labelW2->Text=L"W2 = "+W2.ToString("F2"); labelF1->Text=L"F1 = "+(F1*180/M_PI).ToString("F0"); labelF2->Text=L"F2 = "+(F2*180/M_PI).ToString("F0"); pictureBox1->Invalidate(); } // -------------------------------------------------------------------------- private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) { Graphics^ grafika = e->Graphics; grafika->Clear( Color::White); //colorDialog2->Color); Pen^ pioro=gcnew Pen(System::Drawing::Color::Black); pioro->EndCap=Drawing2D::LineCap::ArrowAnchor; grafika->DrawLine(pioro, ex(Xp),ey(0.0),ex(Xk),ey(0.0)); grafika->DrawLine(pioro, ex(0.0),ey(Yp),ex(0.0),ey(Yk)); pioro->EndCap=Drawing2D::LineCap::NoAnchor; pioro->Width=int( numericUpDownSin1->Value); pioro->Color=panelSin1->BackColor; double yp,y,dx=(Xk-Xp)/pictureBox1->Width; y=A1*cos(W1*Xp+F1); if(checkBoxSin1->Checked==true) for(double x=Xp; xDrawLine(pioro, ex(x-dx),ey(yp), ex(x),ey(y)); } pioro->Width=int( numericUpDownSin2->Value); pioro->Color=panelSin2->BackColor; y=A2*cos(W2*Xp+F2); if(checkBoxSin2->Checked==true) for(double x=Xp; xDrawLine(pioro, ex(x-dx),ey(yp), ex(x),ey(y)); } pioro->Width=int( numericUpDownSin12->Value); pioro->Color=panelSin12->BackColor; y=A1*cos(W1*Xp+F1);+A2*cos(W2*Xp+F2); if(checkBoxSin12->Checked==true) for(double x=Xp; xDrawLine(pioro, ex(x-dx),ey(yp), ex(x),ey(y)); } } // -------------------------------------------------------------------------- private: System::Void pictureBox1_Resize(System::Object^ sender, System::EventArgs^ e) { pictureBox1->Invalidate(); } // -------------------------------------------------------------------------- private: System::Void pictureBox1_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { int xe=e->X,ye=e->Y; double xr=rzx( xe),yr=rzy( ye); tLabelEkr->Text=L"(x,y)ekr = ("+xe.ToString()+L"; "+ye.ToString()+L")"; tLabelRzecz->Text=L"(x,y)rzecz = ("+xr.ToString("F2")+L"; "+yr.ToString("F2")+L")"; } // -------------------------------------------------------------------------- private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) { timer1->Enabled=checkBox1->Checked; } // -------------------------------------------------------------------------- private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { hScrollBarF2->Value=(hScrollBarF2->Value+3)%hScrollBarF2->Maximum; F2=hScrollBarF2->Value*M_PI/180.0; labelF2->Text=L"F2 = "+(F2*180/M_PI).ToString("F0"); pictureBox1->Invalidate(); } // -------------------------------------------------------------------------- private: System::Void panel_Click(System::Object^ sender, System::EventArgs^ e) { Panel ^panel=(Panel^) sender; colorDialog1->Color=panel->BackColor; if(colorDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) panel->BackColor = colorDialog1->Color; pictureBox1->Invalidate(); } // -------------------------------------------------------------------------- private: System::Void textBox2_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) { if(e->KeyValue==13) textBox_Leave( sender, gcnew EventArgs()); } // -------------------------------------------------------------------------- private: System::Void textBox_Leave(System::Object^ sender, System::EventArgs^ e) { try { Xp=Convert::ToDouble(textBoxXp->Text); Xk=Convert::ToDouble(textBoxXk->Text); Yp=Convert::ToDouble(textBoxYp->Text); Yk=Convert::ToDouble(textBoxYk->Text); } catch(...) { textBoxXp->Text=Xp.ToString(); textBoxXk->Text=Xk.ToString(); textBoxYp->Text=Yp.ToString(); textBoxYk->Text=Yk.ToString(); } pictureBox1->Invalidate(); } // -------------------------------------------------------------------------- }; }